package br.edu.ufcg.dsc.actions.unit;

import java.util.List;

import org.apache.struts2.config.Result;
import org.apache.struts2.dispatcher.ServletDispatcherResult;

import br.edu.ufcg.dsc.actions.BaseAdminAction;
import br.edu.ufcg.dsc.domain.Library;
import br.edu.ufcg.dsc.domain.Resource;
import br.edu.ufcg.dsc.domain.Unit;
import br.edu.ufcg.dsc.domain.User;
import br.edu.ufcg.dsc.domain.UserType;
import br.edu.ufcg.dsc.services.LibraryService;
import br.edu.ufcg.dsc.services.ResourceService;
import br.edu.ufcg.dsc.services.UserService;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

@Result(name = "success", type = ServletDispatcherResult.class, value = "/jsp/unit/unit.jsp")

public class CreateAction extends BaseAdminAction implements Preparable, ModelDriven<Unit>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List<Resource> resources;
	private Unit unit;
	private String unitId;
	private List<Library> libraries;
	private List<User> teachers, librarians;
	
	@Override
	protected String executeIfAdmin() {
		return SUCCESS;
	}

	public List<Resource> getResources() {
		return resources;
	}

	public void setResources(List<Resource> resources) {
		this.resources = resources;
	}

	public List<Library> getLibraries() {
		return libraries;
	}

	public void setLibraries(List<Library> libraries) {
		this.libraries = libraries;
	}

	public void prepare() throws Exception {
		resources = ResourceService.findAllResources();
		libraries = LibraryService.findAll();
		librarians = UserService.findByType(UserType.LIBRARIAN.name());
		teachers = UserService.findByType(UserType.TEACHER.name());
	}

	public Unit getModel() {
		return unit;
	}

	public String getUnitId() {
		return unitId;
	}

	public void setUnitId(String unitId) {
		this.unitId = unitId;
	}

	public List<User> getTeachers() {
		return teachers;
	}

	public void setTeachers(List<User> teachers) {
		this.teachers = teachers;
	}

	public List<User> getLibrarians() {
		return librarians;
	}

	public void setLibrarians(List<User> librarians) {
		this.librarians = librarians;
	}
}
